package com.mx.tool.form.window.zh;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.text.UnicodeUtil;
import cn.hutool.jwt.JWT;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;

import javax.swing.*;

/**
 * @Author: 徐建鹏.
 * @create: 2021-11-10 15:12
 * @Description:
 */
public class JwtWindow {
    private JPanel jPanel;
    private JTextArea contentArea;
    private JTextArea showArea;
    private JButton button;
    private JButton clearButton;


    public JwtWindow() {
        button.addActionListener(e -> {
            showArea.setText("");
            String content = contentArea.getText();
            if(StringUtils.isNotBlank(content)){
                JWT jwt = JWT.create().parse(content);
                if(jwt != null){
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("header",jwt.getHeaders());
                    jsonObject.put("payload",jwt.getPayloads());
                    showArea.setText(JSON.toJSONString(jsonObject,true));
                }
            }
        });
        clearButton.addActionListener(e -> {
            contentArea.setText("");
            showArea.setText("");
        });
    }

    public JPanel getContent() {
        return jPanel;
    }
}
